Kuo['apijson/admin_log'] = {
    url: plug + "apijson" + FENGE + "admin_log" + FENGE,
    YESNO:["否","是"],
    OFF:["关闭","开启"],
    $grade:{ "-1":"游客","0":"普通用户","88":"超级管理"},
    TYPE:["静态资源","Node.js","PHP"],
    init: function () {
        Kuo['apijson/admin_log'].get();
    },
    edit(OBJ, diercai) {
        if (diercai != "add") {
            diercai = "put";
            var title = "查看日志";
        } else {
            var title = "查看日志";
        }
        window.UIMUI = Array();
        var D = OBJ.data;
        var BIAO = [];
        var html = '<form name="form" id="form" class="layui-form ' + $class + '">';

        
        let head = D.head;
        try {
            head =  JSON.stringify(  JSON.parse(D.head),null,4);
        } catch (error) {}
        D.head = head;
        let body = D.body;
        try {
            body =  JSON.stringify(  JSON.parse(D.body),null,4);
        } catch (error) {}
        D.body = body;

        BIAO = [

           'id($$)id($$)hidden($$)($$)id($$)' + D.id,
           'route($$)请求url路径($$)text($$)($$)请求url路径($$)' + D.route,
            'method($$)请求method($$)text($$)($$)请求method($$)' + D.method,
            'head($$)head头部信息($$)textarea($$)($$)head头部信息($$)' + D.head,
            'body($$)请求body json内容($$)textarea($$)($$)请求body json内容($$)' + D.body,
            'ip($$)ip($$)text($$)($$)ip($$)' + D.ip,
            'sessionid($$)sessionid($$)text($$)($$)sessionid($$)' + D.sessionid,
            'atime($$)时间($$)time($$)($$)时间($$)' + D.atime,
            'uid($$)用户uid($$)text($$)($$)用户uid($$)' + D.uid,
            'status($$)返回($$)textshow($$)($$)返回($$)' + D.status,
            'grade($$)角色级别($$)select($$)($$)Kuo["apijson/admin_log"].$grade($$)' + D.grade

        ];



        for (var z in BIAO) {
            html += jsfrom(BIAO[z]);
        }

        html += jsfrom('ff' + $class + '($$)($$)submit($$)($$)layer.close(OPID);Kuo[\'apijson/admin_log\'].init()($$)重放($$)tijiao');
        html += "</form>";
        OPID = layer.open({
            type: 1,
            zIndex: 10000,
            title: title,
            area: ['100%', '100%'],
            fixed: true,
            maxmin: true,
            content: html,
            success: function (layero, index) {
            }
        });

        layui.form.on('submit(ff' + $class + ')', function (formdata) {
            formdata = formdata.field;
            formdata.Format = 'json';

            $.ajax({
                type :formdata.method,
                url : formdata.route,
                data : formdata.body,
                processData : false,
                contentType : false, 
                contentType: "application/json",
                success : function(result) {

                    layer.close(OPID);
                    Kuo['apijson/admin_log'].get();

                    layer.open({
                        type: 1, // page 层类型
                        area: ['500px', '500px'],
                        title: '重放结果',
                        shade: 0.6, // 遮罩透明度
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: false, // 允许全屏最小化
                        anim: 1, // 0-6 的动画形式，-1 不开启
                        content: '<pre style="width:100%;height:100%;" contenteditable="true" class="layui-textarea">'+JSON.stringify(result,null,4)+'</pre>'
                      });

              


                },
                error : function(e){
                  layer.msg(e.statusText,{offset: 'c'});
                }
            });


            return false;
        });

        layui.form.render();

    },soso(id){
       
        setTimeout(function(){
            if(Kuo['payment/admin_order'] && typeof(Kuo['payment/admin_order'].soso) != "undefined" ){
                Kuo['payment/admin_order'].soso({ id:id});
            }
        },600);
        
    },del(OBJ) {
        var fromdata = {
            Format: 'json',
            id: OBJ.data.id
        };
        apptongxin(Kuo['apijson/admin_log'].url + TOKEN + FENGE + 'del', fromdata, function (data) {
            if (data.token && data.token != "") {
                TOKEN = data.token;
            }
            if (data.code == 99) {
                layer.msg("请登陆", {
                    offset: 'c',
                    time: 2000
                }, function () {
                    loadjs("home");
                });
            } else if (data.code == 1) {
                OBJ.del();
            } else {
                layer.msg(data.msg, {
                    zIndex: 99999,
                    offset: 'c',
                    time: 2000
                });
            }
        });
    },
    add() {
        Kuo['apijson/admin_log'].edit(
            {data:{"id":0,"route":"","method":"","head":"","body":"","ip":"","sessionid":"","atime":"0","uid":"0","grade":"-1","status":"0"}}, 
        'add');

    },
    get() {
        $("#LAY_app_body ." + $class).html('<style> .' + $class + ' .qfys0{color:#FF5722;} .' + $class + ' .qfys1{color:#009688;}.' + $class + ' .qfys2{color:green;}.' + $class + ' .qfys3{color:#1E9FFF;}</style><div class="layui-fluid"><div class="layui-card"><div class="layui-card-body" style="padding: 15px;">'
            +
            '<div class="' + $class + 'saixuan" style="display:none;margin-bottom:8px;"><form name="form" class="layui-form"> <div class="layui-inline" style="width:158px;"> <input class="layui-input so_var" name="so_route" autocomplete="off" placeholder="路径搜索"> </div>  <div class="layui-inline" style="width:88px;"> <input class="layui-input so_var" name="so_uid" autocomplete="off" placeholder="uid"> </div>  <div class="layui-inline" style="width:158px;"> <input class="layui-input so_var" name="so_session" autocomplete="off" placeholder="sessionid"> </div>   <div class="layui-inline" style="width:158px;"> <input class="layui-input so_var" name="so_ip" autocomplete="off" placeholder="ip"> </div><button class="layui-btn" lay-event="sousuo" lay-submit lay-filter="tijiao' + $class + '">搜索</button></form> </div>'
            +
            '<table class="layui-hide" id="apijson' + $class + '" lay-filter="apijson' + $class + '"></table></div></div></div>');
        layui.table.render({
            elem: '#apijson' + $class,
            url: Kuo['apijson/admin_log'].url + TOKEN + FENGE + 'get',
            toolbar: '<div><a class="layui-btn " lay-event="refresh"><i class="layui-icon layui-icon-refresh-3"></i> 刷新</a> <a class="layui-btn layui-btn-danger" lay-event="saixuan"><i class="layui-icon layui-icon-search"></i>筛选</a> </div>',
            cols: [
                [{
                    field: 'id',
                    title: 'ID',
                    width: 88,
                },{
                    field: "route",
                    title: "请求路径"
                   
                },{
                    field: "method",
                    width:88,
                    title: "method"
                   
                },{
                    field: "ip",
                    width:168,
                    title: "ip"
                   
                },{
                    field: "sessionid",
                    width:188,
                    title: "session"
                   
                },{
                    field: "grade",
                    title: "角色",
                    width:108,
                    templet: function (d) {

                        return Kuo['apijson/admin_log'].$grade[d.grade];
                    }
                   
                },{
                    field: "uid",
                    width:88,
                    title: "uid"
                   
                },{
                    field: "status",
                    width:88,
                    title: "返回"
                   
                }, {
                    field: "atime",
                    title: "时间",
                    width:188,
                    templet: function (d) {

                        return time(d.atime);
                    }
                }, {

                    
                    title: '操作',
                    width:158,
                    templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>查看</a>  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                    }
                }]
            ],
            limit: 20,
            page: true,
            done: function (data, curr, count) {
                if (data.token && data.token != "") {
                    TOKEN = data.token;
                }

                
                if( data.$grade){

                    let $grade = {};
                    for(let m in data.$grade){
                        let data_ = data.$grade[m];
                        let jixi = data_.split('@');
                        $grade[jixi[0]] = jixi[1];
                    }
                    Kuo['apijson/admin_log'].$grade = $grade;
                }
              

            }
        });
        layui.table.on('toolbar(apijson' + $class + ')', function (obj) {
            if (obj.event === 'add') {
                Kuo['apijson/admin_log'].add();
            } else if (obj.event === 'refresh') {
                layer.closeAll();
                Kuo['apijson/admin_log'].init();
            } else if (obj.event === 'saixuan') {
                $("." + $class + "saixuan").toggle();
            }
        });

        layui.table.on('tool(apijson' + $class + ')', function (obj) {
            if (obj.event === 'del') {
                layer.confirm('真的要删除吗?', function (index) {
                    Kuo['apijson/admin_log'].del(obj);
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                Kuo['apijson/admin_log'].edit(obj);
            }

        });

        layui.form.on('submit(tijiao' + $class + ')', function (formdata) {
            formdata = formdata.field;
            var zuhesou = {};
            $('.' + $class + 'saixuan .so_var').each(function (i, v) {
                if ($(v).val() != "") {
                    zuhesou[$(v).attr('name').replace('so_', '')] = $(v).val();
                }
            });
            layui.table.reload('apijson' + $class, {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                url: Kuo['apijson/admin_log'].url + TOKEN + FENGE + 'get',
                where: zuhesou
            });
            return false;
        });

        layui.table.render();
    }
}
Kuo['apijson/admin_log'].init();